var vm = new Vue({
	el: "#app",
	data: {
		musicList: [],
		commentList: [],
		targetSong: "蔡依林",
		musicId: "",
		musicUrl: "",
		mvId: "",
		mvUrl: "",
		playImg: "../images/play.png",
		pointImg: "../images/pointStop.png",
		mvImgUrl: "../images/mv.png",
		pointStatus: false, //正在播放，显示暂停图标
		albumId: "", //专辑id
		coverImg: "../images/mv.png", //封面图
		isPlaying:false,
		playMvFlag:false,
		isPaused:true,
		color:-1
	},
	methods: {
		/**
		 * 网易云接口: https://autumnfish.cn
		 * */
		searchMusic: function() {
			var that = this;
			axios.get("https://autumnfish.cn/search?limit=30&keywords=" + that.targetSong).then(function(response) {
				that.musicList = response.data.result.songs;
				// console.log(response.data.result.songs[0].album.id);
			}).catch(function(err) {
				console.log(err);
			});
		},
		playMusic: function(item, index) {
			var that = this;
			that.albumId = item.album.id;
			that.musicId = item.id;
			that.playMvFlag = false;
			that.$refs.myVideo.src = "";
			that.commentList ="";
			that.color = index;
			// 播放点击的音乐
			axios.get("https://autumnfish.cn/song/url?id=" + that.musicId).then(function(response) {
				that.musicUrl = response.data.data[0].url;
				that.$refs.myAudio.src = that.musicUrl;
				// console.log(response);
			}).catch(function(err) {
				console.log(err);
			});
			// 把点击的item封面添加到封面区
			axios.get("https://autumnfish.cn/album?id=" + that.albumId).then(function(response) {
				that.coverImg = response.data.album.picUrl;
				// console.log(response.data.album.picUrl);
			}).catch(function(err) {
				console.log(err);
			});
			//获取评论
			this.getComment();
		},
		getComment: function() {
			var that = this;
			axios.get("https://autumnfish.cn/comment/hot?type=0&limit=10&id=" + that.musicId).then(function(response) {
				that.commentList = response.data.hotComments;
				console.log(response.data);
			}).catch(function(err) {
				console.log(err);
			});
		},
		playMV: function(item) {
			var that = this;
			that.$refs.myAudio.src = "";
			that.commentList ="";
			that.mvId = item.mvid;
			//获取mv资源
			axios.get("https://autumnfish.cn/mv/url?id=" + that.mvId).then(function(response) {
				console.log(response.data.data.url);
				that.mvUrl = response.data.data.url;
				that.$refs.myVideo.src = that.mvUrl;
			}).catch(function(err) {
				console.log(err);
			});
			that.playMvFlag = true;
			//获取mv评论
			axios.get("https://autumnfish.cn/comment/mv?id=" + that.mvId).then(function(response) {
				console.log(response.data.comments);
				that.commentList = response.data.comments;
			}).catch(function(err) {
				console.log(err);
			});
			
		},
		play:function(){
			console.log("play");
			this.isPlaying = true;
			this.isPaused = false;
			// this.pointImg = "../images/pointPlay.png";
		},
		pause:function(){
			console.log("pause");
			this.isPaused = true;
			this.isPlaying = false;
			// this.pointImg = "../images/pointStop.png";
		}
	}
});